Ext.ux.SurveyPanel = function() {
	var desktop = MyDesktop.getDesktop();
	var win_survey = desktop.getWindow('survey-win');
	if (!win_survey) {
		var _jsonReader1 = new Ext.data.JsonReader({
					root : 'results',
					totalProperty : 'totalCount'
				}, [{
							name : 'id',
							mapping : 'id'
						},{
							name : 'content',
							mapping : 'content'
						},{
							name : 'date',
							mapping : 'date'
						}]);
		var ds_survey = new Ext.data.Store({
					proxy : new Ext.data.HttpProxy({
								url : '/admin/question.jhtml?method=getQuestions'
							}),
					reader : _jsonReader1
				});
		var cm_keyword = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),
				new Ext.grid.CheckboxSelectionModel(), {
					header : "编号",
					width : 80,
					sortable : true,
					dataIndex : 'id'
				},{
					header : "标题",
					width : 200,
					sortable : true,
					dataIndex : 'content'
				},  {
					header : "创建时间",
					width : 100,
					sortable : true,
					dataIndex : 'date'
				}]);
		var grid_survey = new Ext.grid.GridPanel({
			region : "center",
			cm : cm_keyword,
			sm : new Ext.grid.CheckboxSelectionModel(),
			border : false,
			loadMask : {
				msg : "数据加载中，请稍等..."
			},
			store : ds_survey,
			viewConfig : {
				forceFit : true
			},
			bbar : new Ext.PagingToolbar({
						pageSize : 20,
						store : ds_survey,
						displayInfo : true
					}),
			tbar : [{
                    text: '添加',
                    tooltip: '添加调查',
                    iconCls: 'add',
                    handler: function(){
				// 开始创建Add面板
				var addCForm = new Ext.FormPanel( {
					layout :'form',
					border :false,
					labelSeparator :'：',
					frame :true,
					labelWidth :60,
					labelAlign :'left',
					buttonAlign :'right',
					bodyStyle :'padding:5px',
					width :330,
					fileUpload :true, // 允许上传文件
					enctype :'multipart/form-data',
					items : [ {
						xtype :'textfield',
						fieldLabel :'标题',
						name :'content',
						id:'content',
						maxLength :500,
						maxLengthText :'不能超过500个字符',
						allowBlank :false,
						blankText :'名称不能为空！',
						anchor :'96%'
					} ],
					buttons : [ {
						id :'btnSave',
						text :'保 存',
						handler : function() {
						
						if (addCForm.form.isValid())// 客户端先验证数据
						{
							//var kkk = encodeURIComponent(addCForm.findById('keyword').getValue());

							// this.disabled = true; //禁止保存按钮，防止多次提交
						addCForm.form.doAction('submit', {
							url :'/admin/question.jhtml?method=addQuestion',
						//	method :'get',
						//	params:{keyword:kkk},
							waitTitle :'请稍候',
							waitMsg :'正在提交表单数据，请稍候...',
							success : function(form, action) {
								getAlertMessage("提示","操作成功!",Ext.MessageBox.WARNING);
								addCForm.form.reset();
								this.disabled = false;
								newC1win.close();
								
								ds_survey.load( {
									params : {
										start :0,
										limit :20
									}
								});// 重新加载grid的数据
							},
							failure : function() {
								getAlertMessage("提示","保存失败!",Ext.MessageBox.WARNING);
								this.disabled = false;
							}
						})
					}
				}

					}, {
						text :'取 消',
						handler : function() {
						newC1win.close();
					}
					} ]
				});
			
					newC1win = new Ext.Window( {
						xtype :'window',
						title :'添加热词',
						buttonAlign :'right',
						closable :true,
						layout :'fit',
						modal :'true',
						width :350,
						height :150,
						closeAction :'close',
						plain :true,
						items :addCForm

					});
					newC1win.show();

			}
                },'-',{
                
			text : '删除',
			tooltip : '挂起选中的一个',
			iconCls : 'remove',
			handler : function() {

				var rows = grid_survey.getSelectionModel().getSelections();// 返回值为
				// Record
				// 数组
				if (rows.length == 0) {
					getAlertMessage("警告","最少选择一条信息，进行删除!",Ext.MessageBox.WARNING);
				} else {
					Ext.MessageBox.confirm('提示框', '您确定要进行该操作？', function(btn) {
						if (btn == 'yes') {

							if (rows) {
								for (var i = 0; i < rows.length; i++) {
									var conn = new Ext.data.Connection();
									conn.request({
										url : '/admin/question.jhtml?method=deleteQuestion',
										params : {
											questionId : rows[i]
													.get("id")
										}

									});

									break;
								}

							}
							loadDs(ds_survey,20);
						}
					});
				} // 弹出对话框警告
			}
		
                },'-',{
                
															text : '查看选项',
															tooltip : '查看选中的一列',
															cls : 'x-btn-text-icon',
															icon : '/static/images/desktop/icon/16551842.gif',
															handler : function() {
																var rows = grid_survey
																		.getSelectionModel()
																		.getSelections();// 返回值为
																if (rows.length == 0) {
																	getAlertMessage("提示","最少选择一条信息，进行操作!",Ext.MessageBox.WARNING);
																} else {
																	publicCId = rows[0].get("id");
																	commentType = 1;
																	loadClass("Ext.ux.OptionPanel","option-win");
																} // 弹出对话框警告
															}
														
                }]
		});
		win_survey = desktop.createWindow({
					id : 'survey-win',
					title : '调查管理',
					width : 740,
					height : 480,
					iconCls : 'icon-grid',
					shim : false,
					animCollapse : false,
					constrainHeader : true,
					layout : 'fit',
					items : grid_survey
				});
		grid_survey.store.load({
					params : {
						start : 0,
						limit : 20
					},
					callback : listError
				});
	}
	win_survey.show();
}